package com.mxchip.livestarmobile.mobile.ui.mine

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import com.mxchip.livestarmobile.R
import com.mxchip.livestarmobile.mobile.ContactDetailActivity
import com.mxchip.livestarmobile.mobile.state.AppConstant
import com.mxchip.livestarmobile.mobile.LoginActivity
import com.mxchip.livestarmobile.mobile.repository.RoomClientRepository
import com.mxchip.livestarmobile.mobile.util.Utils
import com.orhanobut.hawk.Hawk
import kotlinx.android.synthetic.main.fragment_mine.*

class MineFragment : Fragment() {

    private val mineViewModel by viewModels<MineViewModel>()

    override fun onDestroyView() {
        super.onDestroyView()
    }

    override fun onCreateView(inflater: LayoutInflater,
                              container: ViewGroup?, savedInstanceState: Bundle?): View? {

        return inflater.inflate(R.layout.fragment_mine, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mineViewModel.hxbNumber.observe(viewLifecycleOwner, Observer { s -> text_hxb_number.text = s })

        mineViewModel.test().observe(viewLifecycleOwner, Observer {
            Log.e("MineFragment", "list: $it")
        })

        view_logout.setOnClickListener {

            Hawk.delete(AppConstant.SP_LOGIN_TOKEN)
            Hawk.delete(AppConstant.SP_LOGIN_PHONE_NUMBER)
            Hawk.delete(AppConstant.SP_LOGIN_USER_ID)
            Hawk.delete(AppConstant.SP_LUXX_NUMBER)
            Hawk.delete(AppConstant.SP_LUXX_ROOM_ID)

            RoomClientRepository.destroy()

            startActivity(Intent(context, LoginActivity::class.java))

            activity?.finish()
        }

        view_delete2.setOnClickListener {
            val intent = Intent(context, AboutActivity::class.java)
            startActivity(intent)
        }
    }

    override fun onResume() {
        super.onResume()

    }
}